{
  "metadata": {
    "toc-showcode": false,
    "toc-autonumbering": false,
    "toc-showtags": false,
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "version_major": 2,
        "version_minor": 0,
        "state": {
          "5fb425d3185b4cce92be92c1375094d5": {
            "model_name": "LayoutModel",
            "model_module": "@jupyter-widgets/base",
            "model_module_version": "2.0.0",
            "state": {}
          },
          "63dd6a1378da41b7a73f6e3134b2fd04": {
            "model_name": "SliderStyleModel",
            "model_module": "@jupyter-widgets/controls",
            "model_module_version": "2.0.0",
            "state": {
              "description_width": ""
            }
          },
          "9d812769e6724f83ae4a6dc4839b77bd": {
            "model_name": "FloatSliderModel",
            "model_module": "@jupyter-widgets/controls",
            "model_module_version": "2.0.0",
            "state": {
              "step": 0.1,
              "behavior": "drag-tap",
              "layout": "IPY_MODEL_5fb425d3185b4cce92be92c1375094d5",
              "style": "IPY_MODEL_63dd6a1378da41b7a73f6e3134b2fd04"
            }
          }
        }
      }
    },
    "language_info": {
      "codemirror_mode": {
        "name": "python",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8"
    },
    "kernelspec": {
      "name": "python",
      "display_name": "Python (Pyodide)",
      "language": "python"
    }
  },
  "nbformat_minor": 4,
  "nbformat": 4,
  "cells": [
    {
      "cell_type": "code",
      "source": "import micropip\nawait micropip.install(\"aiocoap[prettyprint]\")\nimport aiocoap\nctx = await aiocoap.Context.create_client_context()",
      "metadata": {
        "trusted": true
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "await micropip.install('ipywidgets')\nimport ipywidgets as widgets\nslider = widgets.FloatSlider()\nslider",
      "metadata": {
        "trusted": true
      },
      "execution_count": 2,
      "outputs": [
        {
          "execution_count": 2,
          "output_type": "execute_result",
          "data": {
            "text/plain": "FloatSlider(value=0.0)",
            "application/vnd.jupyter.widget-view+json": {
              "version_major": 2,
              "version_minor": 0,
              "model_id": "9d812769e6724f83ae4a6dc4839b77bd"
            }
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": "from aiocoap import resource\nimport cbor2\n\nclass Position(resource.Resource):\n    def __init__(self, widget):\n        super().__init__()\n        self.widget = widget\n    async def render_get(self, request):\n        # We should check some options here, or bug the aiocoap author\n        # about better abstractions for typed resources\n        return aiocoap.Message(content_format=60,\n                payload=cbor2.dumps(self.widget.value))\n    async def render_put(self, request):\n        self.widget.value = cbor2.loads(request.payload)\n        return aiocoap.Message(code=aiocoap.CHANGED)\n\nroot = resource.Site()\nroot.add_resource(['.well-known', 'core'],\n    resource.WKCResource(root.get_resources_as_linkheader))\nroot.add_resource(['position'], Position(slider))\nctx.serversite = root",
      "metadata": {
        "trusted": true
      },
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": "from aiocoap.resourcedirectory.client.register import Registerer\nregisterer = Registerer(\n    ctx,\n    \"coaps+ws://rd.coap.amsuess.com\",\n    lt=60,\n    registration_parameters={\n        \"ep\": \"jupyter\",\n        \"proxy\": \"on\",\n    },\n)",
      "metadata": {
        "trusted": true
      },
      "execution_count": 4,
      "outputs": []
    }
  ]
}